{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Marvel API 使用说明\n",
    "\n",
    "漫威官网开放了很多对开发者友好的API，本文是对python库： **marvel** 的使用说明，用法很简单。\n",
    "\n",
    "安装：pip install marvel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import marvel\n",
    "from IPython.display import Image, HTML, display\n",
    "\n",
    "PUBLIC_KEY = '你的公钥'\n",
    "PRIVATE_KEY = '你的密钥'\n",
    "\n",
    "m = marvel.Marvel(PUBLIC_KEY, PRIVATE_KEY)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "一共可以获取6钟对象，即[开发人员](https://developers.zomato.com/documentation)中列出的 角色，漫画，创作者，事件，系列和故事。每个对象都返回官方[docs](https://developer.marvel.com/docs)中提到的相应响应json 。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 角色 object\n",
    "character = m.characters\n",
    "\n",
    "# 漫画 object\n",
    "comic = m.comics\n",
    "\n",
    "# 创作者 object\n",
    "creator = m.creators\n",
    "\n",
    "# 事件 object\n",
    "event = m.events\n",
    "\n",
    "# 系列 object\n",
    "serie = m.series\n",
    "\n",
    "# 故事 object\n",
    "story = m.stories"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 模块示例\n",
    "### 获取所有角色："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Get All Characters\n",
    "character.all()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 获取搜索中的角色："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Get Specific Characters\n",
    "name = input('请输入要查询的英雄（英文，可只输入开头）：')\n",
    "print('搜索中...')\n",
    "\n",
    "select_characters = character.all(nameStartsWith=name)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "输入下面这些搜索关键词试试\n",
    "- captain america\n",
    "- super\n",
    "\n",
    "然后运行下面的代码进行结果展示："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(select_characters)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 获得单一角色："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(character.get(1011334))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 获取一些角色的漫画："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(character.comics(1011334))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "同样，可以将相同的逻辑应用于不同的对象，例如："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "all_stores = story.all()\n",
    "events = story.events(id)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "下面是这些object各自专属的属性，可以随意尝试:\n",
    "\n",
    "Characters\n",
    "- all\n",
    "- get\n",
    "- comics\n",
    "- events\n",
    "- series\n",
    "- stories\n",
    "\n",
    "Comics\n",
    "- all\n",
    "- get\n",
    "- characters\n",
    "- creators\n",
    "- events\n",
    "- stories\n",
    "\n",
    "Creators\n",
    "- all\n",
    "- get\n",
    "- comics\n",
    "- events\n",
    "- series\n",
    "- stories\n",
    "\n",
    "Events\n",
    "- all\n",
    "- get\n",
    "- characters\n",
    "- comics\n",
    "- creators\n",
    "- series\n",
    "- stories\n",
    "\n",
    "Series\n",
    "- all\n",
    "- get\n",
    "- characters\n",
    "- comics\n",
    "- creators\n",
    "- events\n",
    "- stories\n",
    "\n",
    "Stories\n",
    "- all\n",
    "- get\n",
    "- characters\n",
    "- comics\n",
    "- creators\n",
    "- events\n",
    "- series"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
